<template>
	<view class="page">
		<view class="section">
			<u-search v-model="searchContent" @blur="toSearch" placeholder="搜索科目" :show-action="false" height="80"
				search-icon-size="46"></u-search>
		</view>
		<view class="flex margin-top-xl">
			<view class="flex-1 section" style="height: 90vh; overflow-y: auto;">
				<view class="text-size-xs br-b-f5" v-for="(subject,subjectIndex) in subjectList">
					<view class="home-title padding-sm"
						@click="openLike('/pages/balance-detail/balance-detail',subject)">
						<view class="flex-1 margin-left-xl">
							<view>{{subject.code}}</view>
							<view>{{subject.fullName}}</view>
						</view>
						<uni-icons type="right" size="14"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import accountBook from '../../js/api/accountBook'
	export default {
		data() {
			return {
				subjectIndex: 0,
				subjectList: [],
				searchContent: '',
				dataList:[],
			}
		},
		onLoad() {
			this.loadData()
		},
		methods: {
			toSearch(e) {
				if (e) {
					this.subjectList = this.dataList.filter(item => {
						return item.name.toLowerCase().includes(this.searchContent);
					});
				} else {
					this.subjectList = this.dataList
				}
			},
			loadData() {
				accountBook.subject({
					// currencyId:uni.getStorageSync(app.globalData.data.cache_currency_id),
					// levelStart: 1,
					// levelEnd: 4,
				}).then((res) => {
					this.dataList = this.subjectList= res
				})
			},
			openLike(url, item) {
				console.log(item)
				uni.navigateTo({
					url: url + "?subjectId=" + item.id + "&subjectCode=" + item.code
				})
			},
		}
	}
</script>

<style>
	.home-title {
		display: flex;
		align-items: center;
		justify-content: space-between
	}
</style>